package com.water_work_form.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.water_work_form.entity.BasicWater;
import com.water_work_form.result.Result;
import com.water_work_form.result.ResultCodeEnum;
import com.water_work_form.result.ResultUtil;
import com.water_work_form.service.BasicWaterService;
import com.water_work_form.util.RandomIdUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 基础表——纯水信息 前端控制器
 * </p>
 *
 * @author xuke
 * @since 2023-08-01
 */

@Api(tags = {"纯水信息 前端控制器"})
@RestController
@RequestMapping("/basic-water")
public class BasicWaterController {

    @Autowired
    BasicWaterService basicWaterService;

    /**
     * 纯水信息 新增项目
     * @param basicWater 新数据
     * @return result code 0成功
     */
    @ApiOperation("新增")
    @PostMapping("/add")
    public Result addBasicWater(@RequestBody BasicWater basicWater){
        basicWater.setId(RandomIdUtil.createRandomId());
        basicWaterService.save(basicWater);
        return ResultUtil.success(ResultCodeEnum.SUCCESS,basicWater);
    }

    /**
     * 纯水信息 查看（分页）
     * @param type 一级纯水机型号
     * @param current 分页 当前页
     * @param size 分页 每页数据量
     */
    @ApiOperation("查看(分页)")
    @GetMapping("/pageList")
    public Result listBasicWater(@RequestParam("type") String type, @RequestParam("current") Integer current,
                              @RequestParam("size") Integer size){
        IPage<BasicWater> page = basicWaterService.listWater(type, current, size);
        return ResultUtil.success(ResultCodeEnum.SUCCESS, page);
    }

    /**
     * 纯水信息 根据id删除项目
     * @param id 删除项目的id
     * @return result code 0成功
     */
    @ApiOperation("删除")
    @DeleteMapping("/delete")
    public Result deleteBasicWater(@RequestParam("id") Long id){
        basicWaterService.removeById(id);
        return ResultUtil.success(ResultCodeEnum.SUCCESS);
    }

    /**
     * 更新项目
     * @param basicWater 更新的数据
     * @return result code 0成功
     */
    @ApiOperation("更新")
    @PostMapping("/update")
    public Result updateBasicWater(@RequestBody BasicWater basicWater){
        basicWaterService.updateById(basicWater);
        return ResultUtil.success(ResultCodeEnum.SUCCESS);
    }

}

